home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Tool Chest / !Interfaces / Universal Interfaces 2.0a1 / CIncludes / OSUtils.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-17  |  14.2 KB  |  576 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        OSUtils.h
  3.  
  4.      Copyright:    © 1984-1994 by Apple Computer, Inc.
  5.                  All rights reserved.
  6.  
  7.      Version:    Universal Interfaces 2.0a1.  ETO #15, MPW prerelease.  Sunday, July 17, 1994. 
  8.  
  9.      Bugs?:        If you find a problem with this file, send the file and version
  10.                  information (from above) and the problem description to:
  11.  
  12.                      Internet:    apple.bugs@applelink.apple.com
  13.                      AppleLink:    APPLE.BUGS
  14.  
  15. */
  16.  
  17. #ifndef __OSUTILS__
  18. #define __OSUTILS__
  19.  
  20.  
  21. #ifndef __TYPES__
  22. #include <Types.h>
  23. #endif
  24. /*    #include <ConditionalMacros.h>                                */
  25.  
  26. #ifndef __MIXEDMODE__
  27. #include <MixedMode.h>
  28. #endif
  29.  
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33.  
  34. #if GENERATINGPOWERPC
  35. #pragma options align=mac68k
  36. #endif
  37.  
  38. #ifdef __CFM68K__
  39. #pragma lib_export on
  40. #endif
  41.  
  42.  
  43. enum {
  44.     useFree                        = 0,
  45.     useATalk                    = 1,
  46.     useAsync                    = 2,
  47.     useExtClk                    = 3,                            /*Externally clocked*/
  48.     useMIDI                        = 4,
  49. /* Environs Equates */
  50.     curSysEnvVers                = 2,                            /*Updated to equal latest SysEnvirons version*/
  51. /* Machine Types */
  52.     envMac                        = -1,
  53.     envXL                        = -2,
  54.     envMachUnknown                = 0,
  55.     env512KE                    = 1,
  56.     envMacPlus                    = 2,
  57.     envSE                        = 3,
  58.     envMacII                    = 4,
  59.     envMacIIx                    = 5,
  60.     envMacIIcx                    = 6,
  61.     envSE30                        = 7,
  62.     envPortable                    = 8,
  63.     envMacIIci                    = 9,
  64.     envMacIIfx                    = 11,
  65. /* CPU types */
  66.     envCPUUnknown                = 0
  67. };
  68.  
  69. enum {
  70.     env68000                    = 1,
  71.     env68010                    = 2,
  72.     env68020                    = 3,
  73.     env68030                    = 4,
  74.     env68040                    = 5,
  75. /* Keyboard types */
  76.     envUnknownKbd                = 0,
  77.     envMacKbd                    = 1,
  78.     envMacAndPad                = 2,
  79.     envMacPlusKbd                = 3,
  80.     envAExtendKbd                = 4,
  81.     envStandADBKbd                = 5,
  82.     envPrtblADBKbd                = 6,
  83.     envPrtblISOKbd                = 7,
  84.     envStdISOADBKbd                = 8,
  85.     envExtISOADBKbd                = 9,
  86.     false32b                    = 0,                            /*24 bit addressing error*/
  87.     true32b                        = 1,                            /*32 bit addressing error*/
  88. /* result types for RelString Call */
  89.     sortsBefore                    = -1,                            /*first string < second string*/
  90.     sortsEqual                    = 0,                            /*first string = second string*/
  91.     sortsAfter                    = 1                                /*first string > second string*/
  92. };
  93.  
  94. enum {
  95. /* Toggle results */
  96.     toggleUndefined                = 0,
  97.     toggleOK                    = 1,
  98.     toggleBadField                = 2,
  99.     toggleBadDelta                = 3,
  100.     toggleBadChar                = 4,
  101.     toggleUnknown                = 5,
  102.     toggleBadNum                = 6,
  103.     toggleOutOfRange            = 7,                            /*synonym for toggleErr3*/
  104.     toggleErr3                    = 7,
  105.     toggleErr4                    = 8,
  106.     toggleErr5                    = 9,
  107. /* Date equates */
  108.     smallDateBit                = 31,                            /*Restrict valid date/time to range of Time global*/
  109.     togChar12HourBit            = 30,                            /*If toggling hour by char, accept hours 1..12 only*/
  110.     togCharZCycleBit            = 29,                            /*Modifier for togChar12HourBit: accept hours 0..11 only*/
  111.     togDelta12HourBit            = 28,                            /*If toggling hour up/down, restrict to 12-hour range (am/pm)*/
  112.     genCdevRangeBit                = 27,                            /*Restrict date/time to range used by genl CDEV*/
  113.     validDateFields                = -1,
  114.     maxDateField                = 10,
  115.     eraMask                        = 0x0001,
  116.     yearMask                    = 0x0002,
  117.     monthMask                    = 0x0004,
  118.     dayMask                        = 0x0008,
  119.     hourMask                    = 0x0010,
  120.     minuteMask                    = 0x0020,
  121.     secondMask                    = 0x0040,
  122.     dayOfWeekMask                = 0x0080,
  123.     dayOfYearMask                = 0x0100,
  124.     weekOfYearMask                = 0x0200,
  125.     pmMask                        = 0x0400,
  126.     dateStdMask                    = 0x007F                        /*default for ValidDate flags and ToggleDate TogglePB.togFlags*/
  127. };
  128.  
  129. enum {
  130.     eraField,
  131.     yearField,
  132.     monthField,
  133.     dayField,
  134.     hourField,
  135.     minuteField,
  136.     secondField,
  137.     dayOfWeekField,
  138.     dayOfYearField,
  139.     weekOfYearField,
  140.     pmField,
  141.     res1Field,
  142.     res2Field,
  143.     res3Field
  144. };
  145.  
  146. typedef SignedByte LongDateField;
  147.  
  148.  
  149. enum {
  150.     dummyType,
  151.     vType,
  152.     ioQType,
  153.     drvQType,
  154.     evType,
  155.     fsQType,
  156.     sIQType,
  157.     dtQType,
  158.     nmType
  159. };
  160.  
  161. typedef SignedByte QTypes;
  162.  
  163.  
  164. enum {
  165.     OSTrap,
  166.     ToolTrap
  167. };
  168.  
  169. typedef SignedByte TrapType;
  170.  
  171. struct SysParmType {
  172.     UInt8                            valid;
  173.     UInt8                            aTalkA;
  174.     UInt8                            aTalkB;
  175.     UInt8                            config;
  176.     short                            portA;
  177.     short                            portB;
  178.     long                            alarm;
  179.     short                            font;
  180.     short                            kbdPrint;
  181.     short                            volClik;
  182.     short                            misc;
  183. };
  184. typedef struct SysParmType SysParmType, *SysPPtr;
  185.  
  186. typedef struct QElem QElem;
  187.  
  188. typedef QElem *QElemPtr;
  189.  
  190. struct QElem {
  191.     QElemPtr                        qLink;
  192.     short                            qType;
  193.     short                            qData[1];
  194. };
  195. typedef struct QHdr QHdr;
  196.  
  197. typedef QHdr *QHdrPtr;
  198.  
  199. struct QHdr {
  200.     short                            qFlags;
  201.     QElemPtr                        qHead;
  202.     QElemPtr                        qTail;
  203. };
  204. /*
  205.         DeferredTaskProcPtr uses register based parameters on the 68k and cannot
  206.         be written in or called from a high-level language without the help of
  207.         mixed mode or assembly glue.
  208.  
  209.         In:
  210.          => dtParam         A1.L
  211. */
  212.  
  213. #if GENERATINGCFM
  214. typedef UniversalProcPtr DeferredTaskUPP;
  215. #else
  216. typedef Register68kProcPtr DeferredTaskUPP;
  217. #endif
  218.  
  219. struct DeferredTask {
  220.     QElemPtr                        qLink;
  221.     short                            qType;
  222.     short                            dtFlags;
  223.     DeferredTaskUPP                    dtAddr;
  224.     long                            dtParam;
  225.     long                            dtReserved;
  226. };
  227. typedef struct DeferredTask DeferredTask, *DeferredTaskPtr;
  228.  
  229. struct SysEnvRec {
  230.     short                            environsVersion;
  231.     short                            machineType;
  232.     short                            systemVersion;
  233.     short                            processor;
  234.     Boolean                            hasFPU;
  235.     Boolean                            hasColorQD;
  236.     short                            keyBoardType;
  237.     short                            atDrvrVersNum;
  238.     short                            sysVRefNum;
  239. };
  240. typedef struct SysEnvRec SysEnvRec;
  241.  
  242. struct MachineLocation {
  243.     Fract                            latitude;
  244.     Fract                            longitude;
  245.     union {
  246.         char                            dlsDelta;                /*signed byte; daylight savings delta*/
  247.         long                            gmtDelta;                /*must mask - see documentation*/
  248.     } u;
  249. };
  250.  
  251. typedef struct MachineLocation MachineLocation;
  252.  
  253. struct DateTimeRec {
  254.     short                            year;
  255.     short                            month;
  256.     short                            day;
  257.     short                            hour;
  258.     short                            minute;
  259.     short                            second;
  260.     short                            dayOfWeek;
  261. };
  262. typedef struct DateTimeRec DateTimeRec;
  263.  
  264. typedef wide LongDateTime;
  265.  
  266. union LongDateCvt {
  267.     wide                            c;
  268.         struct {
  269.             UInt32                            lHigh;
  270.             UInt32                            lLow;
  271.         }                            hl;
  272. };
  273. typedef union LongDateCvt LongDateCvt;
  274.  
  275. union LongDateRec {
  276.         struct {
  277.             short                            era;
  278.             short                            year;
  279.             short                            month;
  280.             short                            day;
  281.             short                            hour;
  282.             short                            minute;
  283.             short                            second;
  284.             short                            dayOfWeek;
  285.             short                            dayOfYear;
  286.             short                            weekOfYear;
  287.             short                            pm;
  288.             short                            res1;
  289.             short                            res2;
  290.             short                            res3;
  291.         }                            ld;
  292.     short                            list[14];                    /*Index by LongDateField!*/
  293.         struct {
  294.             short                            eraAlt;
  295.             DateTimeRec                        oldDate;
  296.         }                            od;
  297. };
  298. typedef union LongDateRec LongDateRec;
  299.  
  300. typedef char DateDelta;
  301.  
  302. struct TogglePB {
  303.     long                            togFlags;                    /*caller normally sets low word to dateStdMask=$7F*/
  304.     ResType                            amChars;                    /*from 'itl0', but uppercased*/
  305.     ResType                            pmChars;                    /*from 'itl0', but uppercased*/
  306.     long                            reserved[4];
  307. };
  308. typedef struct TogglePB TogglePB;
  309.  
  310. typedef short ToggleResults;
  311.  
  312. enum {
  313.     uppDeferredTaskProcInfo = kRegisterBased
  314.          | REGISTER_ROUTINE_PARAMETER(1, kRegisterA1, SIZE_CODE(sizeof(long)))
  315. };
  316.  
  317. #if GENERATINGCFM
  318. #define NewDeferredTaskProc(userRoutine)        \
  319.         (DeferredTaskUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppDeferredTaskProcInfo, GetCurrentArchitecture())
  320. #else
  321. #define NewDeferredTaskProc(userRoutine)        \
  322.         ((DeferredTaskUPP) (userRoutine))
  323. #endif
  324.  
  325. #if GENERATINGCFM
  326. #define CallDeferredTaskProc(userRoutine, dtParam)        \
  327.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppDeferredTaskProcInfo, (dtParam))
  328. #else
  329. /* (*DeferredTaskProcPtr) cannot be called from a high-level language without the Mixed Mode Manager */
  330. #endif
  331.  
  332. extern pascal void LongDateToSeconds(const LongDateRec *lDate, LongDateTime *lSecs)
  333.  FOURWORDINLINE(0x2F3C, 0x8008, 0xFFF2, 0xA8B5);
  334. extern pascal void LongSecondsToDate(LongDateTime *lSecs, LongDateRec *lDate)
  335.  FOURWORDINLINE(0x2F3C, 0x8008, 0xFFF0, 0xA8B5);
  336. extern pascal ToggleResults ToggleDate(LongDateTime *lSecs, LongDateField field, DateDelta delta, short ch, const TogglePB *params)
  337.  FOURWORDINLINE(0x2F3C, 0x820E, 0xFFEE, 0xA8B5);
  338. extern pascal short ValidDate(const LongDateRec *vDate, long flags, LongDateTime *newSecs)
  339.  FOURWORDINLINE(0x2F3C, 0x820C, 0xFFE4, 0xA8B5);
  340. extern pascal Boolean IsMetric(void)
  341.  THREEWORDINLINE(0x3F3C, 0x0004, 0xA9ED);
  342. extern pascal SysPPtr GetSysPPtr(void)
  343.  THREEWORDINLINE(0x2EBC, 0x0000, 0x01F8);
  344.  
  345. #if !GENERATINGCFM
  346. #pragma parameter __D0 ReadDateTime(__A0)
  347. #endif
  348. extern pascal OSErr ReadDateTime(unsigned long *time)
  349.  ONEWORDINLINE(0xA039);
  350.  
  351. #if !GENERATINGCFM
  352. #pragma parameter GetDateTime(__A0)
  353. #endif
  354. extern pascal void GetDateTime(unsigned long *secs)
  355.  TWOWORDINLINE(0x20B8, 0x020C);
  356.  
  357. #if !GENERATINGCFM
  358. #pragma parameter __D0 SetDateTime(__D0)
  359. #endif
  360. extern pascal OSErr SetDateTime(unsigned long time)
  361.  ONEWORDINLINE(0xA03A);
  362.  
  363. #if !GENERATINGCFM
  364. #pragma parameter SetTime(__A0)
  365. #endif
  366. extern pascal void SetTime(const DateTimeRec *d)
  367.  TWOWORDINLINE(0xA9C7, 0xA03A);
  368.  
  369. #if !GENERATINGCFM
  370. #pragma parameter GetTime(__A0)
  371. #endif
  372. extern pascal void GetTime(DateTimeRec *d)
  373.  THREEWORDINLINE(0x2038, 0x020C, 0xA9C6);
  374. extern pascal void DateToSeconds(const DateTimeRec *d, unsigned long *secs);
  375.  
  376. #if !GENERATINGCFM
  377. #pragma parameter SecondsToDate(__D0, __A0)
  378. #endif
  379. extern pascal void SecondsToDate(unsigned long secs, DateTimeRec *d)
  380.  ONEWORDINLINE(0xA9C6);
  381. extern pascal void SysBeep(short duration)
  382.  ONEWORDINLINE(0xA9C8);
  383.  
  384. #if !GENERATINGCFM
  385. #pragma parameter __D0 DTInstall(__A0)
  386. #endif
  387. extern pascal OSErr DTInstall(DeferredTaskPtr dtTaskPtr)
  388.  ONEWORDINLINE(0xA082);
  389. #if GENERATING68K
  390. extern char GetMMUMode( void )
  391.     TWOWORDINLINE( 0x1038, 0x0CB2 ); /* MOVE.B $0CB2, D0 */
  392.  
  393. #if !GENERATINGCFM
  394. #pragma parameter SwapMMUMode(__A0)
  395. #endif
  396. extern pascal void SwapMMUMode(SInt8 *mode)
  397.  THREEWORDINLINE(0x1010, 0xA05D, 0x1080);
  398. #else
  399. #define SwapMMUMode(x) (*(SInt8*)(x) = true32b)
  400. #endif
  401. #if SystemSixOrLater
  402.  
  403. #if !GENERATINGCFM
  404. #pragma parameter __D0 SysEnvirons(__D0, __A0)
  405. #endif
  406. extern pascal OSErr SysEnvirons(short versionRequested, SysEnvRec *theWorld)
  407.  ONEWORDINLINE(0xA090);
  408. #else
  409. extern pascal OSErr SysEnvirons(short versionRequested, SysEnvRec *theWorld);
  410. #endif
  411.  
  412. #if !GENERATINGCFM
  413. #pragma parameter Delay(__A0, __A1)
  414. #endif
  415. extern pascal void Delay(long numTicks, long *finalTicks)
  416.  TWOWORDINLINE(0xA03B, 0x2280);
  417. /*
  418.     GetTrapAddress and SetTrapAddress are obsolete and should not
  419.     be used. Always use NGetTrapAddress and NSetTrapAddress instead.
  420.     The old routines will not be supported for PowerPC apps.
  421. */
  422. #if OLDROUTINENAMES && !GENERATINGCFM
  423.  
  424. #if !GENERATINGCFM
  425. #pragma parameter __A0 GetTrapAddress(__D0)
  426. #endif
  427. extern pascal UniversalProcPtr GetTrapAddress(short trapNum)
  428.  ONEWORDINLINE(0xA146);
  429.  
  430. #if !GENERATINGCFM
  431. #pragma parameter SetTrapAddress(__A0, __D0)
  432. #endif
  433. extern pascal void SetTrapAddress(UniversalProcPtr trapAddr, short trapNum)
  434.  ONEWORDINLINE(0xA047);
  435. #endif
  436. extern pascal UniversalProcPtr NGetTrapAddress(short trapNum, TrapType tTyp);
  437. extern pascal void NSetTrapAddress(UniversalProcPtr trapAddr, short trapNum, TrapType tTyp);
  438.  
  439. #if !GENERATINGCFM
  440. #pragma parameter __A0 GetOSTrapAddress(__D0)
  441. #endif
  442. extern pascal UniversalProcPtr GetOSTrapAddress(short trapNum)
  443.  ONEWORDINLINE(0xA346);
  444.  
  445. #if !GENERATINGCFM
  446. #pragma parameter SetOSTrapAddress(__A0, __D0)
  447. #endif
  448. extern pascal void SetOSTrapAddress(UniversalProcPtr trapAddr, short trapNum)
  449.  ONEWORDINLINE(0xA247);
  450.  
  451. #if !GENERATINGCFM
  452. #pragma parameter __A0 GetToolTrapAddress(__D0)
  453. #endif
  454. extern pascal UniversalProcPtr GetToolTrapAddress(short trapNum)
  455.  ONEWORDINLINE(0xA746);
  456.  
  457. #if !GENERATINGCFM
  458. #pragma parameter SetToolTrapAddress(__A0, __D0)
  459. #endif
  460. extern pascal void SetToolTrapAddress(UniversalProcPtr trapAddr, short trapNum)
  461.  ONEWORDINLINE(0xA647);
  462.  
  463. #if !GENERATINGCFM
  464. #pragma parameter __A0 GetToolboxTrapAddress(__D0)
  465. #endif
  466. extern pascal UniversalProcPtr GetToolboxTrapAddress(short trapNum)
  467.  ONEWORDINLINE(0xA746);
  468.  
  469. #if !GENERATINGCFM
  470. #pragma parameter SetToolboxTrapAddress(__A0, __D0)
  471. #endif
  472. extern pascal void SetToolboxTrapAddress(UniversalProcPtr trapAddr, short trapNum)
  473.  ONEWORDINLINE(0xA647);
  474. extern pascal OSErr WriteParam(void);
  475.  
  476. #if !GENERATINGCFM
  477. #pragma parameter Enqueue(__A0, __A1)
  478. #endif
  479. extern pascal void Enqueue(QElemPtr qElement, QHdrPtr qHeader)
  480.  ONEWORDINLINE(0xA96F);
  481.  
  482. #if !GENERATINGCFM
  483. #pragma parameter __D0 Dequeue(__A0, __A1)
  484. #endif
  485. extern pascal OSErr Dequeue(QElemPtr qElement, QHdrPtr qHeader)
  486.  ONEWORDINLINE(0xA96E);
  487. extern long SetCurrentA5(void)
  488.  THREEWORDINLINE(0x200D, 0x2A78, 0x0904);
  489.  
  490. #if !GENERATINGCFM
  491. #pragma parameter __D0 SetA5(__D0)
  492. #endif
  493. extern long SetA5(long newA5)
  494.  ONEWORDINLINE(0xC18D);
  495. #if !SystemSevenOrLater
  496. extern pascal void Environs(short *rom, short *machine);
  497. #endif
  498. extern pascal OSErr HandToHand(Handle *theHndl);
  499.  
  500. #if !GENERATINGCFM
  501. #pragma parameter __D0 PtrToXHand(__A0, __A1, __D0)
  502. #endif
  503. extern pascal OSErr PtrToXHand(const void *srcPtr, Handle dstHndl, long size)
  504.  ONEWORDINLINE(0xA9E2);
  505. extern pascal OSErr PtrToHand(const void *srcPtr, Handle *dstHndl, long size);
  506.  
  507. #if !GENERATINGCFM
  508. #pragma parameter __D0 HandAndHand(__A0, __A1)
  509. #endif
  510. extern pascal OSErr HandAndHand(Handle hand1, Handle hand2)
  511.  ONEWORDINLINE(0xA9E4);
  512.  
  513. #if !GENERATINGCFM
  514. #pragma parameter __D0 PtrAndHand(__A0, __A1, __D0)
  515. #endif
  516. extern pascal OSErr PtrAndHand(const void *ptr1, Handle hand2, long size)
  517.  ONEWORDINLINE(0xA9EF);
  518.  
  519. #if !GENERATINGCFM
  520. #pragma parameter __D0 InitUtil
  521. #endif
  522. extern pascal OSErr InitUtil(void)
  523.  ONEWORDINLINE(0xA03F);
  524. #if GENERATING68K
  525. extern pascal Boolean SwapInstructionCache(Boolean cacheEnable);
  526. extern pascal void FlushInstructionCache(void)
  527.  TWOWORDINLINE(0x7001, 0xA098);
  528. extern pascal Boolean SwapDataCache(Boolean cacheEnable);
  529. extern pascal void FlushDataCache(void)
  530.  TWOWORDINLINE(0x7003, 0xA098);
  531. extern pascal void FlushCodeCache(void)
  532.  ONEWORDINLINE(0xA0BD);
  533.  
  534. #if !GENERATINGCFM
  535. #pragma parameter FlushCodeCacheRange(__A0, __A1)
  536. #endif
  537. extern pascal void FlushCodeCacheRange(void *address, unsigned long count)
  538.  TWOWORDINLINE(0x7009, 0xA098);
  539. #endif
  540.  
  541. #if !GENERATINGCFM
  542. #pragma parameter ReadLocation(__A0)
  543. #endif
  544. extern pascal void ReadLocation(MachineLocation *loc)
  545.  FOURWORDINLINE(0x203C, 0x000C, 0x00E4, 0xA051);
  546.  
  547. #if !GENERATINGCFM
  548. #pragma parameter WriteLocation(__A0)
  549. #endif
  550. extern pascal void WriteLocation(const MachineLocation *loc)
  551.  FOURWORDINLINE(0x203C, 0x000C, 0x00E4, 0xA052);
  552. #if GENERATINGPOWERPC
  553. extern pascal UniversalProcPtr *GetTrapVector(short trapNumber);
  554. #endif
  555. #if OLDROUTINENAMES
  556. #define LongDate2Secs(lDate, lSecs) LongDateToSeconds(lDate, lSecs)
  557. #define LongSecs2Date(lSecs, lDate) LongSecondsToDate(lSecs, lDate)
  558. #define IUMetric() IsMetric()
  559. #define Date2Secs(d, secs) DateToSeconds(d, secs)
  560. #define Secs2Date(secs, d) SecondsToDate(secs, d)
  561. #endif
  562.  
  563. #ifdef __CFM68K__
  564. #pragma lib_export off
  565. #endif
  566.  
  567. #if GENERATINGPOWERPC
  568. #pragma options align=reset
  569. #endif
  570.  
  571. #ifdef __cplusplus
  572. }
  573. #endif
  574.  
  575. #endif /* __OSUTILS__ */
  576.